<template>
  <!-- 主单详情  订单数量 -->
  <el-dialog
    :title="$t('订单数量')"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="90%"
    :before-close="cancel">
    <!-- *************************************搜索区************************************* -->
    <el-form :model="queryParams" ref="queryParams" size="small" :inline="true">
      <!-- <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList"
          >搜索</el-button
        >
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="queryParams.orderNo = ''"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>
    <el-table
      show-summary
      :summary-method="
        (e) =>
          handleSum(e, [
            'turnover',
            'tax',
            'payAmount',
            'freightSkuAmount',
            'skuTotalAmount',
            'useShopCouponAmount',
            'usePlatformCouponAmount',
            'useCouponTotal',
            'usePoints',
            'returnPoints',
          ])
      "
        ref="TableRef"  :data="tableData">
      <!-- 序号 -->
      <el-table-column :label="$t('序号')" align="center" type="index" />
      <!-- 订单id -->
      <el-table-column show-overflow-tooltip :label="$t('订单号')" align="center" prop="orderNo" />
      <!-- 收货人 -->
      <el-table-column show-overflow-tooltip :label="$t('收货人')" align="center" prop="receiveName">
      </el-table-column>
      <!-- 收货人电话 -->
      <el-table-column show-overflow-tooltip :label="$t('收货人电话')" align="center" prop="receivePhone">
      </el-table-column>
      <!-- 收货人地址 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('收货人地址')"
        align="center"
        width="120"
        prop="address1">
        <template slot-scope="{ row }">
          <span>{{ handleReceiveAddress(row) }}</span>
        </template>
      </el-table-column>

      </el-table-column>
      <!-- 是否错误 -->
      <el-table-column show-overflow-tooltip :label="$t('是否错误')" align="center" prop="error">
        <template slot-scope="{ row }">
          <!-- 是否有错误 0：无 1：有 -->
          <div v-if="row.error == 0">
            <!-- 无 -->
            {{ $t('否') }}
          </div>
          <div v-if="row.error == 1">
            <el-link type="danger" :underline="false">
              <!-- 有 -->
              {{ $t('是') }}
            </el-link>
          </div>
        </template>
      </el-table-column>
      <!-- 是否重复 -->
      <el-table-column show-overflow-tooltip :label="$t('是否重复')" align="center" prop="repeatFlag">
        <template slot-scope="{ row }">
          <div v-if="row.repeatFlag == 1">
            <!-- 是 -->
            {{ $t('是') }}
          </div>
          <div v-if="row.repeatFlag == 0">
            <!-- 否 -->
            {{ $t('否') }}
          </div>
        </template>
      </el-table-column>
      <!-- 营业额 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('营业额') + '(JPY)'"
        align="center"
        prop="turnover"
        width="100" />
      <!-- 消费税 -->
      <el-table-column show-overflow-tooltip :label="$t('消费税')" align="center" prop="tax" />
      <!-- 付款金额 -->
      <el-table-column show-overflow-tooltip :label="$t('付款金额')" align="center" prop="payAmount" />
      <!-- 运费合计商品金额 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('运费合计商品金额')"
        align="center"
        prop="freightSkuAmount" />
      <!-- 商品合计金额 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('商品合计金额')"
        align="center"
        prop="skuTotalAmount" />
      <!-- 使用店铺发行优惠券 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('使用店铺发行优惠券')"
        align="center"
        prop="useShopCouponAmount" />
      <!-- 使用平台发行优惠券 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('使用平台发行优惠券')"
        align="center"
        prop="usePlatformCouponAmount" />
      <!-- 使用优惠券合计 -->
      <el-table-column
        show-overflow-tooltip
        :label="$t('使用优惠券合计')"
        align="center"
        prop="useCouponTotal" />
      <!-- 使用积分 -->
      <el-table-column show-overflow-tooltip :label="$t('使用积分')" align="center" prop="usePoints" />
      <!-- 返点 -->
      <el-table-column show-overflow-tooltip :label="$t('返点')" align="center" prop="returnPoints" />
      <el-table-column label="sku" align="center" prop="sku" :width="skuWidth">
        <template slot-scope="{ row }">
          <div class="sku-list">
            <div v-for="item in row.skus" class="sku-list-item">
              <div class="skuNo">{{ item.skuNo }}</div>
              <el-image
                fit="contain"
                style="width: 30px; height: 30px"
                 :key="Math.random()"
v-hover="item.imgUrl"
                :src="item.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'" />
              <div>{{ item.orderSkuNum }}</div>
            </div>
          </div>
        </template>
      </el-table-column>

    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">
        <!-- 关闭 -->
        {{ $t('关闭') }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { distributionOrder } from '@/api/distribution/orderBatchs/index'
import handleSum from '@/utils/handleSum'

export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  name: 'orderNum',
  props: {
    /**
     * orderBatchId
     */
     ListData: {
      type: Array,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      handleSum,
      skuWidth: 0,
      tableData: [],
      queryParams: {},
    }
  },
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.getList()
      }
    },
  },
  methods: {
    handleReceiveAddress(row) {
      return (
        (row.address1 || '') +
        (row.address2 || '') +
        (row.address3 || '') +
        (row.address4 || '') +
        (row.address5 || '') +
        (row.address6 || '')
      )
    },
    getList() {
      // distributionOrder({
      //   ...this.query,
      //   ...this.queryParams,
      // }).then((res) => {
      //   if (res.code == 200) {
      //   }
      // })
      console.log(this.ListData,'数据');
      this.tableData = this.ListData
      let maxLength = 0
      this.tableData.map((i) => {
        if (i.skus.length > maxLength) {
          maxLength = i.skus.length
        }
      })
      this.skuWidth = maxLength * 200
    },
    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss">
.sku-list {
  display: flex;

  &-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #eee;
    border-radius: 3px;
    padding: 0 2px;
    margin-right: 5px;
    gap: 8px;

    .skuNo {
      white-space: nowrap;
    }
  }
}
</style>
